import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

if (process.env.NODE_ENV === 'development') {
  // console.log('开发环境')
} else {
  console.log('生产环境')
}

import * as directives from '@/directives'
Object.keys(directives).forEach(key => {
  Vue.directive(key, directives[key])
})
console.log(directives, 'directives')

Vue.directive('allow', {
  inserted: function(dom, options) {
    // console.log(dom)
    console.log(options, 'options2')
    const points = store.state.user.userInfo.roles.points
    if (!points.includes(options.value)) {
      dom.style.display = 'none'
    }
  }
})
// // 自动聚焦
// Vue.directive('focus', {
//   inserted: function(dom, options) {
//     // console.log(dom)
//     dom.focus()
//     // console.log(options, 'options')
//   }
// })
// // 默认图片显示
// Vue.directive('imgerror', {
//   inserted: function(dom, options) {
//     // dom就是对应的标签/元素
//     console.log(dom, 123456)
//     // options元素的值
//     console.log(options, 'options')
//     dom.src = options.value
//   }
// })

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
// 权限管理
import '@/permission' // permission control

import myUI from '@/components/index'

Vue.use(myUI)

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)

Vue.config.productionTip = false
import i18n from '@/lang/index'
new Vue({
  el: '#app',
  router,
  store,
  i18n, // this.$i18n
  render: h => h(App)
})
